import {createSlice} from '@reduxjs/toolkit'
 const todo=createSlice({
    name:'todo',
    initialState:{
        // 购物车的数据
        shop:[
            {id:1,name:'小米',price:10,num:0},
            {id:2,name:'苹果',price:5,num:0},
            {id:3,name:'木流牛马',price:66,num:0},
        ]
    },
    reducers:{
        jian:(state,{payload})=>{
          state.shop.map(item=>{
            if(item.id===payload){
                item.num-=1
            }
            return item
          })
        },
        jia:(state,{payload})=>{
          state.shop.map(item=>{
            if(item.id===payload){
                item.num+=1
            }
            return item
          })
        },
    }
 })
   
 export const {jian,jia} =todo.actions
 export default todo.reducer